package com.ss.android.k.d;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;

import com.ss.android.k.b.a;

public final class LayoutInflaterInterceptor implements LayoutInflater.Factory {
    private static final String[] prefixes = new String[]{"android.widget.", "android.webkit.", "android.app."};
    private final LayoutInflater mLayoutInflater;

    public LayoutInflaterInterceptor(LayoutInflater layoutInflater) {
        this.mLayoutInflater = layoutInflater;
        new a();
        new com.ss.android.h.a();
    }

    @Override
    public final View onCreateView(String name, Context context, AttributeSet attributeSet) {
        View view = null;
        if (name.indexOf(".") == -1) {
            for (int i = 0; i < 3; ++i) {
                String prefix = LayoutInflaterInterceptor.prefixes[i];
                try {
                    view = this.mLayoutInflater.createView(name, prefix, attributeSet);
                    if (view == null) {
                        continue;
                    }
                } catch (ClassNotFoundException classNotFoundException) {
                    continue;
                }
                break;
            }
        } else {
            try {
                view = this.mLayoutInflater.createView(name, null, attributeSet);
            } catch (ClassNotFoundException classNotFoundException) {
            }
        }

        if (view instanceof ViewStub && Build.VERSION.SDK_INT >= 21) {
            LayoutInflater layoutInflater = ((ViewStub) view).getLayoutInflater();
            if (layoutInflater != null) {
                layoutInflater.setFactory(new LayoutInflaterInterceptor(layoutInflater));
            }
        }

        return view;
    }
}

